﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;

namespace GSManager
{
    public class LichSu
    {
        private int _STT;
        private string _NguoiDung;
        private string _ThaoTac;
        private DateTime _NgayGio;
        public int STT
        {
            get { return _STT; }
            set { _STT = value; }
        }
        public string NguoiDung
        {
            get { return _NguoiDung; }
            set { _NguoiDung = value; }
        }
        public string ThaoTac
        {
            get { return _ThaoTac; }
            set { _ThaoTac = value; }
        }
        public DateTime NgayGio
        {
            get { return _NgayGio; }
            set { _NgayGio = value; }
        }
        public void ThemLichSu()
        {
            OleDbConnection ketnoi = KetNoi.KetNoiDuLieu();
            string sql = "select Max(STT) from LICHSU";
            OleDbCommand cmd = new OleDbCommand(sql, ketnoi);
            OleDbDataReader r = cmd.ExecuteReader();
            while (r.Read())
            {
                try
                {
                    STT = (int)r[0];
                    STT++;
                }
                catch (Exception) { STT = 1; }
            }
            r.Close();
            sql = "insert into LICHSU values(?,?,?,?)";
            cmd = new OleDbCommand(sql, ketnoi);
            cmd.Parameters.Add("@STT", OleDbType.Integer);
            cmd.Parameters.Add("@NguoiDung", OleDbType.VarWChar);
            cmd.Parameters.Add("@ThaoTac", OleDbType.VarWChar);
            cmd.Parameters.Add("@NgayGio", OleDbType.Date);
            cmd.Parameters[0].Value = STT;
            cmd.Parameters[1].Value = NguoiDung;
            cmd.Parameters[2].Value = ThaoTac;
            cmd.Parameters[3].Value = NgayGio;
            cmd.ExecuteNonQuery();
            ketnoi.Close();
        }
    }
}
